<?php

namespace app\common\validate;

class StoreServicePeriodValidate extends BaseValidate
{
    /**
     * 验证规则
     */
    protected $field = [
        'service_period_id' => '服务时段配置',
        'start_hour'        => '开始时间-小时',
        'start_minute'      => '开始时间-分钟',
        'end_hour'          => '结束时间-小时',
        'end_minute'        => '结束时间-分钟',
        'store_id'          => '门店ID',
        'service_type'      => '服务类型',

    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'update' => [
            'service_type'=>'require|in:1,2',
            'start_hour'=>'require|checkTime',
            'start_minute'=>'require',
            'end_hour'=>'require',
            'end_minute'=>'require',
            'store_id'=>'require',
            'service_period_id'=>'require|integer',
        ],
        'save'   => [
            'service_type'=>'require|in:1,2',
            'start_hour'=>'require|checkTime',
            'start_minute'=>'require',
            'end_hour'=>'require',
            'end_minute'=>'require',
            'store_id'=>'require',
        ],
    ];

    /**
     * 提示消息
     */
    protected $message = [

    ];

    public function checkTime($value, $rule, array $data = []) : bool|string
    {
        $start = sprintf('%s%s' , $data['start_hour'] ,$data['start_minute']);
        $end = sprintf('%s%s' , $data['end_hour'] ,$data['end_minute']);
        if($start > $end){
            return '结束时间不得大于开始时间！';
        }
        return true;
    }

}
